package com.zw.pdm.module.basic.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.entity.basic.Verify;
import com.zw.pdm.module.basic.service.DictCommonService;
import com.zw.pdm.module.basic.service.VerifyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import static com.zw.pdm.constant.Constant.*;

/**
 * @Description: 审核配置接口
 *
 * 权限：
 * basic:verify:view 查看
 * basic:verify:edit 编辑
 *
 * @Author: China.sgl
 * @Date: 2020/8/3 16:11
 */
@Controller
@RequestMapping("/basic/verify")
@SuppressWarnings("all")
public class VerifyController extends BaseController {

    @Autowired
    private VerifyService verifyService;
    @Autowired
    private DictCommonService dictCommonService;

    @GetMapping
    @RequiresPermissions({"basic:verify:view"})
    public String page(Model model) {
        model.addAttribute("repTypes", dictCommonService.findDictByGroupName(GROUP_REPTYPE));
        model.addAttribute("posts", dictCommonService.findDictByGroupName(GROUP_POST));
        return "basic/verify/page";
    }

    /** 审核配置列表 */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"basic:verify:view"})
    public JsonResult list(Verify verify) {
        startPage();
        List<Verify> list = verifyService.findByCondition(verify);
        return jsonResult(list);
    }

    /** 添加审核配置 */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions({"basic:verify:edit"})
    public JsonResult save(Verify verify) {
        return isNotNull(verifyService.saveVerify(verify));
    }

    /** 修改审核配置 */
    @ResponseBody
    @PostMapping("/update")
    @RequiresPermissions({"basic:verify:edit"})
    public JsonResult update(Verify verify) {
        return isNotNull(verifyService.updateVerify(verify));
    }

}
